<template>
  <div>
    <van-nav-bar
      title="个人中心"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <div class="info">
      <div class="login">
        <p class="title">欢迎来到花礼网</p>
        <div v-if="isLogin">
          <img width="50" height="50"  :src="this.isLogin.img_url" alt="img"/>
          <p class="welcome"><span>{{this.isLogin.user_id}}</span></p>
        </div>
        <van-button v-else round type="info" @click="login">登录/注册</van-button>
      </div>
      <div class="list">
        <div class="order" @click="$router.push('/orderlist')">
          <van-icon name="cart-o"/>
          <p >我的订单</p>
        </div>
        <div class="userinfo" @click="$router.push('/myinfo')">
          <van-icon name="smile-o"/>
           <p >我的信息</p>
        </div>
        <div class='history' @click="$router.push('/history')">
          <van-icon name="eye-o"/>
           <p >浏览记录</p>
        </div>
      </div>
    </div>
    <van-divider>到底啦</van-divider>
    <tabbar/>
  </div>
</template>

<script>
import Tabbar from '@components/Tabbar'
import { detailInfo } from '@api/home'
export default {
  data () {
    return {
      name: 'user',
      isLogin: false,
      info: {
      }
    }
  },
  created () {
    this.init()
  },
  methods: {
    init () {
      if (localStorage.getItem('auth_token')) {
        this.isLogin = true
        // 发送请求
        detailInfo().then(res => {
          if (res.data.code === 200) {
            this.isLogin = res.data.data
          }
        })
      }
    },
    onClickLeft () {
      this.$router.go(-1)
    },
    login () {
      this.$router.push('/login')
    }
  },
  components: { Tabbar }
}
</script>

<style lang="scss" scoped>
.info{
  text-align: center;
  .login{
    overflow: hidden;
    img{
      border-radius: 50%;
    }
    .welcome{
      margin: 10px 0;
      font-size: 20px;
      color:black;
      span{
        color: red;
      }
    }
    .title{
      margin: 10px 0;
      font-size: 16px;
      color:white;
    }
    width: 100%;
    min-height: 100px;
    background: #f66;
  }
  .list{
      margin-top: 20px;
    display: flex;
    justify-content: space-around;
    .order,.userinfo,.history{
      display: flex;
      flex-direction: column;
      line-height: 30px;
    }
  }
}
.van-icon{
  font-size: 20px;
}
</style>
